// Playground - noun: a place where people can play

import Cocoa


/***********************************************************************************
 * The Swift Language Learning  Chapter 13: Initialization,Deinitialization,ARC
 ***********************************************************************************/

struct Fahrenheit {
	var temperature: Double
	
	init() {
		temperature = 32.0
	}
}

//var f = Fahrenheit(temperature: 50) //error: if you write only 'init()', you can't do like this
var f = Fahrenheit()

struct Color {
	var someValue: Double = 0.0 //must have a default value
	let red = 0.0, green = 0.0, blue = 0.0
	init(_ red: Double, green: Double, blue: Double) {
		self.red   = red
		self.green = green
		self.blue  = blue
	}
}

//let magenta = Color() //error
let magenta = Color(1.0, green: 0.0, blue: 1.0)


/*
 *class initializer
 */
class Food {
	var name: String
	
	init(name: String) {
		self.name = name
	}
	
	convenience init(){
		self.init(name: "[unnamed]")
	}
}

let nameMeat = Food(name: "Bacon")
let mysteryMeat = Food()


class RecipeIngredient: Food {
	var quantity: Int
	
	init(name: String, quantity: Int) {
		self.quantity = quantity
		super.init(name: name)
	}
	
	convenience init(name: String) {
		self.init(name:name, quantity:1)
	}
	
	
	deinit {
		println("deinit")
	}
}

let oneMysteryItem = RecipeIngredient()
oneMysteryItem.name
oneMysteryItem.quantity

let oneBacon = RecipeIngredient(name: "Bacon")
let sixEggs = RecipeIngredient(name: "Eggs", quantity: 6)


/*
 * ARC
 */
//Strong for default
//unown for weak. unown is not safe, is for a reference that has a value. while weak can used before option value








